package com.citytransport.prokopjuk.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.citytransport.prokopjuk.servlets.LoginServlet;
import com.citytransport.prokopjuk.servlets.RemoveStationServlet;

public class AdminPermisionFilter implements Filter{
    static Logger logger = Logger.getLogger(AdminPermisionFilter.class.getName());
    public void doFilter(ServletRequest req, ServletResponse resp,
	    FilterChain chain) throws IOException, ServletException {
	HttpServletRequest request = (HttpServletRequest)req;
	HttpServletResponse response = (HttpServletResponse) resp;
	logger.info("admin permision filter checking");
	if(request.getSession(true).getAttribute(LoginServlet.USER_ADM)== null){
	    response.sendError(404);
	}else{
	    request.getSession(true).setAttribute(LoginServlet.USER_ADM,Boolean.TRUE);
	}
	chain.doFilter(request, response);	
    }

    public void init(FilterConfig arg0) throws ServletException {
		
    }
    

    public void destroy() {
		
    }

}
